using UnityEngine;
using System.Collections;

public class Button_Move : MonoBehaviour {
	
	public int ButtonIndex;
	Vector3 vector;
	UISlicedSprite backGroundSprite;
	
	// Use this for initialization
	void Start () {
		vector = transform.localPosition;
		backGroundSprite = transform.FindChild("Background").GetComponent<UISlicedSprite>();
		backGroundSprite.alpha = 0;
		
		if(GameData.ScreenRatio == screenRatio.r43)
			transform.localPosition = new Vector3(317.8958f,-361.2618f,vector.z - 300f);
		else if(GameData.ScreenRatio == screenRatio.r1610)
			transform.localPosition = new Vector3(429.6526f,-349.8831f,vector.z - 300f);
		else if(GameData.ScreenRatio == screenRatio.r169)
			transform.localPosition = new Vector3(492.6227f,-349.8831f,vector.z - 300f);
		iTween.MoveTo(gameObject,iTween.Hash("z",0,"time",0.3f,"looptype","none","islocal",true,"easetype",iTween.EaseType.linear,"oncomplete","MoveSetp2","delay",ButtonIndex * 0.4 + 0.5));
		iTween.ValueTo(gameObject,iTween.Hash("from",0f,"to",1f,"time",0.3f,"easetype",iTween.EaseType.linear,"onupdate","AlphaChange","delay",ButtonIndex * 0.4 + 0.5));
	}
	
	void AlphaChange(float alpha)
	{
		backGroundSprite.alpha = alpha;
	}
	
	void MoveSetp2()
	{
		iTween.MoveTo(gameObject,iTween.Hash("position",vector,"time",0.5,"looptype","none","islocal",true,"oncomplete","EnableContrul"));
	}
	
	void EnableContrul()
	{
		transform.GetComponent<UIButton>().enabled = true;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
